package zhongbo.javaweb.instagram.service.model;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import zhongbo.javaweb.instagram.model.Config;

import java.util.List;

/**
 * 说明：
 *
 * @author zhongboWork
 * @version 1.0
 * @since 2021-12-24 17:12
 */
@Service
@Slf4j
public class ConfigService extends BaseService<Config> {

    @Override
    public Config addOrUpdate(Config model) {
        if (model != null) {
            if (model.getThreadSize() < 1) {
                model.setThreadSize(1);
            }
            if (model.getSleepTimeMs() < 0) {
                model.setSleepTimeMs(1000);
            }
        }
        return super.addOrUpdate(model);
    }

    public Config get() {
        Config config;
        List<Config> all = super.findAll();
        if (!all.isEmpty()) {
            config = all.get(0);
        } else {
            config = new Config();
        }
        return config;
    }
}
